﻿@{
    //var web = WebSiteContext.Current.Web;
    Layout = "~/Views/Shared/_Dashboard.cshtml";
    HierarchicalNodeProviderBase provider = ViewBag.Provider;
}
@UIHelper.ImageTitle(Html.Global("Publishing", "Publishing"), "Managing categores and posts.", "~/content/images/icon_publishing_48.png")
<table style="width: 100%;">
    <tr>
        <td colspan="2">
            @{ Ajax.Dna().Toolbar("_toolbarForCategory")
                   .Buttons(buttons =>
                   {
                       //buttons.AddButton(Html.Global("publishing", "Home"), "window.open(\"" + Url.Action("Index", "Article", new { Area = "Publishing" }) + "\");")
                       //    .ImageIcons(Url.Content("~/Content/Images/icon_home_16.png"));
                       //buttons.AddSpliter();
                       buttons.AddButton(Html.Global("publishing", "AddSubCategory"), " _viewer = $('#dna_cat_viewer'); uiHelper.blockUI(_viewer);$.get('" +
                                             Url.Action("Create", "Category", new { Area = "Publishing" }) +
                                             "',{id:$('#CategoryTree').dtree('option','selectedNode').attr('key')},function(htm){$('#dna_cat_viewer').html(htm); uiHelper.unblockUI(_viewer); });")
                                             .ImageIcons(Url.Content("~/Content/Images/icon_add_16.png"));
                       buttons.AddButton(Html.Global("RES_EDIT"), "_loadPublishingViews($('#CategoryTree').dtree('option','selectedNode'),\"" +
                                                                                Url.Action("GetLatestArticles", "Article", new { Area = "Publishing" }) + "\",\"" +
                                                                                Url.Action("Edit", "Category", new { Area = "Publishing" }) + "\");")
                                                                                .ImageIcons(Url.Content("~/Content/Images/edit_page.png"));
                       buttons.AddDropdown(Html.Global("RES_VIEW"))
                           //.Click("window.open(\""++"\");")
                           .ImageIcons(Url.Content("~/content/images/icon_search_page_16.png"))
                           .MenuItems(items =>
                           {
                               items.Add(Html.Global("publishing", "RecentPosts"), "javascript:_getRecentPosts();void(0);").Image(Url.Content("~/content/images/icon_clock_16.png"));
                               items.Add(Html.Global("publishing", "Draft"), "javascript:_getDrafts();void(0);").Image(Url.Content("~/content/images/icon_draft_16.gif"));
                           });

                       buttons.AddSpliter();
                       buttons.AddButton(Html.Global("publishing", "NewPost"), "window.open(\"" + Url.Action("Create", "Article", new { Area = "Publishing" }) + "\");").ImageIcons(Url.Content("~/content/images/icon_new_16.png"));
                       buttons.AddSpliter();
                       buttons.AddButton(Html.Global("RES_HELP"), "window.open(\"" + Url.Help(5) + "\");").ImageIcons(Url.Content("~/content/images/icon_help_16.png"));
                   })
                   .Render();
                //Ajax.Dna().Uploader("btnImportBlogML")
                //    .Options(opts=>{
                //        opts.Action = Url.Action("Import","Category",new {Area="publishing",website=WebSite.CurrentWeb().Name});
                //    })
                //    .Render();
            }
        </td>
    </tr>
    <tr>
        <td style="width: 310px; vertical-align: top;">
            <input id="_selectedKey" type="hidden" value="0" />
            @(Ajax.Dna().TreeView("CategoryTree")
                       .HtmlAttributes(new { style = "width:300px;padding:5px;overflow:auto;margin:0px;" })
                       .DragAndDrop(true)
                       .Options(opts =>
                       {
                           opts.OnNodeSelected = " _viewer = $('#dna_cat_viewer'); $.get('" +
                                     Url.Action("ManageList", "Article", new { Area = "Publishing" }) +
                                     "',{id:$(node).attr('key')},function(htm){$('#dna_cat_viewer').html(htm);  });";
                           opts.OnNodeDropped = "$.post('" + Url.Action("Move", "Category", new { Area = "Publishing" }) +
                           "', { id: ui.node.attr('key'), pos: ui.position,parentID:ui.targetNode.attr('key') });$(\"#CategoryTree\").dtree(\"select\", ui.targetNode);";
                       })
                      .Bind(provider.RootNode, (node) =>
                       {
                           var cat = node.Item as Category;
                           node.NavigateUrl = "javascript:void(0);";
                           if (cat.IsRoot)
                               node.ImageUrl = Url.Content("~/content/images/icon_blog_16.gif");
                           else
                               node.ImageUrl = Url.Content("~/content/images/icon_cat_16.gif");
                           node.Title += " (" + cat.TotalPosts + ")";
                           return true;
                       }).GetHtml())
        </td>
        <td style="padding: 5px; vertical-align: top;">
            <div id="dna_cat_viewer">
                @{ Html.RenderAction("GetLatestArticles", "Article", new { Area = "Publishing" }); }
            </div>
        </td>
    </tr>
</table>
<script type="text/javascript">
    function _getRecentPosts() {
        $("#dna_cat_viewer").load('@Url.Action("GetLatestArticles", "Article", new { Area = "Publishing" })');
    }

    function _getDrafts() {
        $("#dna_cat_viewer").load('@Url.Action("GetDrafts", "Article", new { Area = "Publishing" })');
    }

    function _loadPublishingViews(node, rootUrl, catUrl) {
        var _key = node ? node.attr('key') : "0";
        $('#_selectedKey').val(_key);
        var _viewer = $('#dna_cat_viewer');
        uiHelper.blockUI(_viewer);
        var isRoot = false;
        var selectedNode = $("#CategoryTree").dtree("option", "selectedNode");
        if (selectedNode)
            if ($(selectedNode).parent().attr("id") == "CategoryTree") isRoot = true;

        if (isRoot) {
            $('#dna_cat_viewer').load(rootUrl, function () { uiHelper.unblockUI(_viewer); });
            return;
        }
        $('#dna_cat_viewer').load(catUrl + "/" + _key, function () { uiHelper.unblockUI(_viewer); });
    }
  
</script>
@{ Html.RegisterStartupScript("$(\"#CategoryTree\").dtree(\"select\");"); }
@Html.StartupScripts()
